package mapengine.building
{
import flash.display.MovieClip;
import flash.events.Event;

import framework.core.AssetsManager;
import framework.view.components.graphics.Asset;

import isoengine.world.IsoMapSprite;

/**
 * MapObjectBase
 * @author jliang
 *
 */
public class MapObjectBase extends IsoMapSprite
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function MapObjectBase(descriptor:Object=null)
	{
		super(descriptor);
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	protected var swf:Asset;
	
	protected function get currentAsset():MovieClip
	{
		return asset ? asset.mc : null;
	}
	//==========================================================================
	//  Overridden methods: IsoMapSprite
	//==========================================================================
	override public function set direction(value:int):void
	{
		super.direction = value;
		
		if (asset)
		{
			var tempFrame:int = currentAsset.currentFrame;			
			asset.gotoAndStop("d" + direction);			
			playAnimation(tempFrame);
		}
	}
	
	override public function playAnimation(...args):void
	{
		if (currentAsset) currentAsset.gotoAndPlay(args[0]);
	}
	
	override public function dispose():void
	{
        stopRender();
		if (swf)
		{
			swf.dispose();
			swf = null;
		}
		if (currentAsset)
		{
			currentAsset.stop();
		}
		
		super.dispose();
	}
	//==========================================================================
	//  Protected methods
	//==========================================================================
	protected function loadAsset(url:String, callBack:Function, mode:String = "externalLabs"):void
	{
		if (swf)
		{
			swf.dispose();
			swf = null;
		}
		swf = AssetsManager.loadAsset(url, callBack, null, mode);
	}
	
	protected function initAsset(mc:MovieClip):void
	{
		asset = mc;
		
		mc.gotoAndStop("d" + direction);
		
		sprites = [ mc ];
	}
	
	protected function startRender():void
	{		
		addEventListener(Event.ENTER_FRAME, renderHandler);		
	}
	
	protected function stopRender():void
	{		
		removeEventListener(Event.ENTER_FRAME, renderHandler);		
	}
	//==========================================================================
	//  Event handlers
	//==========================================================================
	protected function renderHandler(event:Event):void
	{
		
	}
}
}






